/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Logger.java
 *
 * Created on 20-feb-2009, 8:30:53
 */
package gui;

import java.awt.Image;
import javax.swing.DefaultComboBoxModel;
import logic.LoginLogic;

/**
 *
 * Author: Gema Lopez García
 * Colaborated: José Iván Palmer García
 * Esta ventana nos permitirá visualizar la ventana para el login de la aplicación.
 */
public class Login extends javax.swing.JFrame {

    private String[] idiomas = {"Español", "Ingles", "Valenciano"};

    /** Creates new form Logger */
    public Login() {
        initComponents();
        this.JCBidioma.setModel(new DefaultComboBoxModel(idiomas));
        this.setLocationRelativeTo(null);
        Image im = new javax.swing.ImageIcon(getClass().getResource("/img/16x16/actions/apply.png")).getImage();
        setIconImage(im);
        this.rootPane.setDefaultButton(JBaceptar);
        alertaVisible(false);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public Login(LoginLogic lg) {
        this();
        this.JBaceptar.addActionListener(lg);
        this.JBresetear.addActionListener(lg);
        alertaVisible(false);
    }

    public String getUsuario() {
        return JTFusuario.getText();
    }

    public String getContrasena() {
        StringBuilder string = new StringBuilder("");
        for (int i = 0; i < jPFContrasenya.getPassword().length; i++) {
            string.append(jPFContrasenya.getPassword()[i]);
        }
        return string.toString();
    }

    public void setContrasena(String contrasenya) {
        this.jPFContrasenya.setText(contrasenya);
    }


    public void setUsuario(String usuario) {
        this.JTFusuario.setText(usuario);
    }
    public void alertaVisible(boolean opcion){
        this.JLBLalerta.setVisible(opcion);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JLusuario = new javax.swing.JLabel();
        JLcontrasenya = new javax.swing.JLabel();
        JTFusuario = new javax.swing.JTextField();
        jPFContrasenya = new javax.swing.JPasswordField();
        JCBrecordar = new javax.swing.JCheckBox();
        JBaceptar = new javax.swing.JButton();
        JBresetear = new javax.swing.JButton();
        JCBidioma = new javax.swing.JComboBox();
        JLBLalerta = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Identificación");
        setAlwaysOnTop(true);
        setResizable(false);

        JLusuario.setText("Usuario");

        JLcontrasenya.setText("Contraseña");

        JCBrecordar.setText("Recordar ");

        JBaceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/16x16/actions/apply.png"))); // NOI18N
        JBaceptar.setText("Aceptar");

        JBresetear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/16x16/actions/reload.png"))); // NOI18N
        JBresetear.setText("Resetear");

        JCBidioma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        JLBLalerta.setForeground(new java.awt.Color(153, 0, 0));
        JLBLalerta.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        JLBLalerta.setText("¡¡Usuario y/o contraseña incorrectos!!");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JLBLalerta, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JLcontrasenya)
                            .addComponent(JLusuario))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JCBrecordar)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPFContrasenya)
                                .addComponent(JTFusuario, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                                .addComponent(JCBidioma, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(JBaceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JBresetear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(77, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JTFusuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLusuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JLcontrasenya)
                    .addComponent(jPFContrasenya, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JCBidioma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JCBrecordar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JBaceptar)
                    .addComponent(JBresetear))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(JLBLalerta)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Login().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JBaceptar;
    private javax.swing.JButton JBresetear;
    private javax.swing.JComboBox JCBidioma;
    private javax.swing.JCheckBox JCBrecordar;
    private javax.swing.JLabel JLBLalerta;
    private javax.swing.JLabel JLcontrasenya;
    private javax.swing.JLabel JLusuario;
    private javax.swing.JTextField JTFusuario;
    private javax.swing.JPasswordField jPFContrasenya;
    // End of variables declaration//GEN-END:variables


    
}
